$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/borderinfo/vipOrderAnalyse',
        datatype: "json",
        colModel: [			
			{ label: '公众号', name: 'gzhName', index: 'gzhName',align: "center", width: 60 },
			{ label: '赠送单数', name: 'giveVipCount', index: 'giveVipCount',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '成交订单数', name: 'dealCount', index: 'dealCount',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '价格98订单', name: 'price98Count', index: 'price98Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '价格168订单', name: 'price168Count', index: 'price168Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '价格298订单', name: 'price298Count', index: 'price298Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '价格398订单', name: 'price398Count', index: 'price398Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '其它价格', name: 'otherPriceCount', index: 'otherPriceCount',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '优惠单数', name: 'totalDiscountCount', index: 'totalDiscountCount',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '优惠5元', name: 'discount5Count', index: 'discount5Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '优惠10元', name: 'discount10Count', index: 'discount10Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '优惠20元', name: 'discount20Count', index: 'discount20Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '优惠30元', name: 'discount30Count', index: 'discount30Count',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
			{ label: '佣金抵扣', name: 'commissionDeductionCount', index: 'commissionDeductionCount',align: "center", width: 60, formatter: function (value,options,rowData) {
					if (value > 0) {
						return "<p style='color: blue'>"+value+"</p>";
					} else {
						return "0";
					}
				}
			},
        ],
		viewrecords: true,
        height: 520,
        rowNum: 50,
		rowList : [50,100],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
		postData:{"gzhCode": vm.q.gzhCode, "beginDate": vm.q.beginDate, "endDate": vm.q.endDate},
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

	$.ajax({
		type: "POST",
		async:false,
		url: baseURL + 'sys/buserinfo/getUserGzhList',
		contentType: "application/json",
		success: function(r){
			if(r.code==0){
				//vm.bbrandinfo=r.brandInfo;
				$("#selectUserGzhList").append(
					"<option value=''>全部平台</option>");
				for(var i=0;i<r.userGzhList.length;i++){
					$("#selectUserGzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
				}
			}
		}
	});
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			gzhCode: '',
			beginDate: null,
			endDate: null
		},
		showList: true
	},
	// 页面加载完毕后触发的事件
	mounted() {
		var vm = this;
		vm.q.beginDate = vm.currentYearFirstDay(); // 默认显示为当前年份第一天
		vm.q.endDate = vm.currentYearLastDay(); // 默认显示为当前年份最后一天
	},
	methods: {
		currentYearFirstDay: function() {
			let now = new Date();
			let y = now.getFullYear(); //年
			return y + '-01-01';
		},
		currentYearLastDay: function() {
			let now = new Date();

			let y = now.getFullYear(); //年
			let nextYear = new Date(y+1, 0, 1);// 明年第一天
			nextYear.setDate(nextYear.getDate() - 1)// 今年最后一天

			let m = nextYear.getMonth() + 1 + ''; //月
			let d = nextYear.getDate() + ''; //日

			m = m.length == 1 ? '0' + m : m;
			d = d.length == 1 ? '0' + d : d;
			return y + '-' + m + '-' + d;
		},
		query: function () {
			vm.reload();
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
				postData:{"gzhCode": vm.q.gzhCode, "beginDate": vm.q.beginDate, "endDate": vm.q.endDate},
                page:page
            }).trigger("reloadGrid");
		}
	}
});